package com.team24.hotel.service.impl;

import com.team24.hotel.domain.Good;
import com.team24.hotel.domain.GoodOrder;
import com.team24.hotel.domain.Supplier;
import com.team24.hotel.domain.SupplierExample;
import com.team24.hotel.mapper.GoodMapper;
import com.team24.hotel.mapper.GoodOrderMapper;
import com.team24.hotel.mapper.SupplierMapper;
import com.team24.hotel.service.GoodOrderService;
import com.team24.hotel.service.GoodService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodOrderServiceImpl implements GoodOrderService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private GoodMapper goodMapper;
    @Autowired
    private GoodOrderMapper goodOrderMapper;
    public List<Supplier> listSupplier(){ return supplierMapper.selectByExample(new SupplierExample());}

    @Override
    public List<GoodOrder> listGoodOrder() {
        return goodOrderMapper.selectAll();
    }

    @Override
    public List<GoodOrder> listHistoryGoodOrder() {
        return goodOrderMapper.selectHistoryAll();
    }

    @Override
    public int insertGoodOrder(GoodOrder goodOrder) {
        return goodOrderMapper.insert(goodOrder);
    }

    @Override
    public void deleteGoodOrderByPrimaryKey(String id) {
        goodOrderMapper.deleteByPrimaryKey(id);

    }

    @Override
    public GoodOrder findGoodOrderById(String id) {
        return (GoodOrder) goodOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveOrUpdate(GoodOrder goodOrder) {
        if(!StringUtils.isNotBlank(goodOrder.getGoodOrderId())){
            return goodOrderMapper.insert(goodOrder);
        }else {
            return goodOrderMapper.updateByPrimaryKeySelective(goodOrder);
        }
    }

    @Override
    public int updateGoodOrderStatusToHistory(String id) {
        return goodOrderMapper.updateGoodOrderStatusToHistory(id);
    }

    @Override
    public int updateGoodOrderStatusToNow(String id) {
        return goodOrderMapper.updateGoodOrderStatusToNow(id);
    }
}

